# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/27 14:10 
@Author  : ZhangShenao 
@File    : bool.py 
@Desc    : bool值判断相关的内置函数
"""

# bool()函数: 判断表达式的结果
# 返回True的条件: 表达式的结果为布尔值True、或非零数字、或非空字符串、或非空列表
print(f'bool(1) is {bool(1)}')  # bool(1) is True
print(f'bool(0) is {bool(0)}')  # bool(0) is False
print(f'bool(\'a\') is {bool('a')}')  # bool('a') is True
print(f'bool(\'\') is {bool('')}')  # bool('') is False
print(f'bool([1]) is {bool([1])}')  # bool([1]) is True
print(f'bool([]) is {bool([])}')  # bool([]) is False

# all() 函数:如果可迭代对象中的所有值,在逐一应用bool(值)后结果都为True,则返回 True;否则返回False
all1 = all([1, 'a', ['x']])
print(f'all1 is {all1}')  # all1 is True
all2 = all([0, 'a', ['x']])
print(f'all2 is {all2}')  # all2 is False

# any() 函数:如果可迭代对象中的任意一个值,在逐一应用bool(值)后结果都为True,则返回True;否则返回False
any1 = any([0, '', [1]])
print(f'any1 is {any1}')  # any1 is True
any2 = any([0, '', []])
print(f'any2 is {any2}')  # any2 is False
